package com.youth.commonutils;

/**
 * ThreadLocal线程隔离
 *
 * @Author：CM
 * @Package：com.youth.commonutils
 * @Project：youth-college
 * @name：UserHolder
 * @Date：2023/5/18 23:35
 * @Filename：UserHolder
 */
public class UserHolder {


    /*实现原理：通过获取每一个线程内的map，得到唯一的用户map，map中存放了用户信息*/

    private static final ThreadLocal<UserDto> CurrentUser = new ThreadLocal<>();

    public static void saveUser(UserDto userDto) {
        CurrentUser.set(userDto);
    }

    public static UserDto getUser() {
        return CurrentUser.get();
    }

    public static void removeUser() {
        CurrentUser.remove();
    }


}
